package observerPattern.observerBPattern;


import java.util.ArrayList;

/**
 * @program: course
 * @author: lsn
 * @create: 2024-05-05 09:54
 * @description: 角色：具体主题(旅行社)
 */
public class TravelAgency implements Subject {
    String tourStartTime;
    String tourMess;
    ArrayList<Observer> personList;

    public TravelAgency() {
        personList = new ArrayList<Observer>();
    }

    @Override
    public void addObserver(Observer o) {
        if (o == null)
            return;
        if (!(personList.contains(o))){
            personList.add(o);
        }

    }

    @Override
    public void deleteObserver(Observer o) {
        if (personList.contains(o)){
            personList.remove(o);
        }
    }

    @Override
    public void notifyObservers() {
        for (Observer observer : personList){
            observer.update(this);
        }
    }
    public void giveMess(String time, String mess){
        tourStartTime = time;
        tourMess = mess;
        notifyObservers();
    }
    public String getTourStartTime() {
        return tourStartTime;
    }

    public String getTourMess() {
        return tourMess;
    }
}

